/*
ID:luongho3
LANG:JAVA
TASK:sort3
 */
package usaco.training.chap2.sec1;

import java.io.File;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class sort3 {

	static int N, count;
	static int[] a,b;
	static int[][] m = new int[4][4];

	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File("sort3.in"));
		PrintStream ps = new PrintStream(new File("sort3.out"));
		System.setOut(ps);
		N = scanner.nextInt();
		a = new int[N];
		b = new int[N];
		for (int i=0;i<N;++i) {
			a[i] = scanner.nextInt();
			b[i] = a[i];
		}
		Arrays.sort(b);
		for (int i=0;i<N;++i) {
			m[a[i]][b[i]]++;
		}
		
		count = 0;
		int m1 = Math.min(m[1][2], m[2][1]);
		m[1][2] -= m1;
		m[2][1] -= m1;
		count += m1;
		
		m1 = Math.min(m[1][3], m[3][1]);
		m[1][3] -= m1;
		m[3][1] -= m1;
		count += m1;
		
		m1 = Math.min(m[2][3], m[3][2]);
		m[2][3] -= m1;
		m[3][2] -= m1;
		count += m1;
		
		count += 2 * m[2][1];
		count += 2 * m[1][2];
		
		System.out.println(count);
	}

}
